/*
 * 4.4.cpp
 *
 *  Created on: 2012-5-18
 *      Author: jawinton
 */

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define LEN 101
#define SIZE 100

char str[SIZE][LEN];
int strNums;

int searchMaxSubString (int min) {
	int subStrLen = strlen(str[min]);
	//bool isFoundMaxSubStr;
	char subStr[LEN], revSubStr[LEN];
	while (subStrLen) {
		for (int start=0; start+subStrLen<=strlen(str[min]); start++) {
			strncpy(subStr, str[min]+start, subStrLen);
			subStr[subStrLen] = '\0';
			for (int i=0; i<subStrLen; i++) {
				revSubStr[subStrLen-i-1] = subStr[i];
			}
			revSubStr[subStrLen] = '\0';
			//isFoundMaxSubStr = true;
			int i;
			for (i=0; i<strNums; i++) {
				if (strstr(str[i], subStr) == NULL && strstr(str[i], revSubStr) == NULL) {
					//isFoundMaxSubStr = false;
					break;
				}
			}
			if (i == strNums) return subStrLen;
		}
		subStrLen --;
	}
	return 0;
}

int main (void) {
	int n;
	cin >> n;
	while (n--) {
		cin >> strNums;
		int minLen = 101, min = 0;
		for (int i=0; i<strNums; i++) {
			cin >> str[i];
			int len = strlen(str[i]);
			if (len < minLen) {
				minLen = len;
				min = i;
			}
		}
		cout << searchMaxSubString(min) << endl;;
	}
	return 0;
}
